<%--
  Created by IntelliJ IDEA.
  User: zeng
  Date: 2016/8/16
  Time: 16:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=utf-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>投诉建议-警风警纪监督员意见建议</title>
    <link type="text/css" href="<c:url value='/resource/wx/newcss/common.css'/>" rel="stylesheet"/>
    <link rel="stylesheet" href="<c:url value='/resource/wechat/newcss/frozen.css'/>">
    <link rel="stylesheet" type="text/css" href="<c:url value='/resource/wechat/newcss/main.css'/>"/>
    <link rel="stylesheet" type="text/css" href="<c:url value='/resource/wechat/newcss/weui.css'/>"/>
    <script type="text/javascript" src="<c:url value='/resource/wx/newjs/jquery-2.0.min.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/resource/wx/newjs/ajaxfileupload.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/resource/wx/newjs/common.js'/>"></script>
    <style type="text/css">
        .ui-radio input{width: 15px;}
    </style>
</head>

<script type="text/javascript">
    var count = 0;

    $(function() {
        var today = new Date();
        var _today = today.getFullYear()+"-"
                + (((today.getMonth()+1)<10)?('0'+(today.getMonth()+1)):(today.getMonth()+1))+"-"
                + ((today.getDate()<10)?('0'+today.getDate()):today.getDate());
        $('#date').val(_today);

        $('#save').click(function(){
            var xm = $('#xm').val();
            var sjhm = $('#sjhm').val();
            var date = $('#date').val();
            var yjzt = $('#yjzt').val();
            var yjjy = $('#yjjy').val();

            if(xm == ''){
                toast("请输入姓名");
                return false;
            }
            if(yjzt == ''){
                toast("请输入意见主题");
                return false;
            }
            if(yjjy == ''){
                toast("请输入意见建议");
                return false;
            }

            var data = {'xm':xm,'sjhm':sjhm,'yjzt':yjzt,'yjjy':yjjy,'tsjylx':'2','ly':'W'};

            $.ajax({
                type : "GET",
                url : "<c:url value='/weixinquery/savetsjyjfjj'/>",
                data : data,
                contentType: "application/json;charset=utf-8",
                async : false,
                dataType : "json",
                success : function(resp){
                    var guid = resp.guid;
                    if(guid != null && guid != ''){
                        ajaxFileUpload(guid);
                        toast("提交投诉建议成功");
                        setTimeout(function () {
                            window.location.href = "<c:url value='/weixinquery/tsjyym'/>";
                        }, 1000);
                    }else{
                        toast("提交投诉建议失败");
                        return false;
                    }
                }
            },'json');

        });
    });

    function changeimg(files) {

        if(files.length > 3 || (files.length + count) > 3){
            toast("上传照片不能大于3张");
            return false;
        }

        for (var i = 0; i < files.length; i++) {
            var file = files[i];
            //判断类型是不是图片
            if(!/image\/\w+/.test(file.type)){
                obj.outerHTML = obj.outerHTML.replace(/(value=\").+\"/i, "$1\"");
                toast("请确保文件为图像类型");
                return false;
            }
            var reader = new FileReader();
            reader.readAsDataURL(file);
            reader.onload = function(e){
                $('#images').append("<li class='weui_uploader_file' style='background-image:url("+this.result+")'>");
            }

            count ++;
        }
    }

    function ajaxFileUpload(guid){
        var data = {'guid' : guid , 'lx' : 'tsjy_jy'};
        $.ajaxFileUpload({
            url: "<c:url value='/upload/uploadAttachment'></c:url>", //用于文件上传的服务器端请求地址
            fileElementId: 'uploadfiles', //文件上传域的ID
            data: data,//参数
            secureuri: false, //是否需要安全协议，一般设置为false
            dataType: 'JSON' //返回值类型 一般设置为json
        });
    }
</script>

<body ontouchstart>
<%--<header class="ui-header ui-header-positive ui-border-b">
    <i class="ui-icon-return" onclick="history.back()"></i>
    <h1>投诉建议</h1>
</header>--%>
<section class="ui-container">
    <h1 class="jzxx_tit">警风警纪监督员意见建议</h1>
    <div style="clear: both;"></div>
    <div class="demo-item">
        <div class="demo-block">
            <div class="ui-form ui-border-t">
                <form action="#">
                    <div class="ui-form-item ui-border-b">
                        <label>
                            <span class="t_red">*</span>姓名：
                        </label>
                        <input id="xm" type="text" placeholder="" maxlength="20"/>
                    </div>
                    <div class="ui-form-item ui-border-b">
                        <label>
                            手机号码：
                        </label>
                        <input id="sjhm" type="text" placeholder="" value="${telephone}" readonly="readonly"/>
                    </div>

                    <input id="date" type="date" hidden="hidden"/>

                    <div class="ui-form-item ui-border-b">
                        <label>
                            <span class="t_red">*</span>意见主题：
                        </label>
                        <input id="yjzt" type="text" placeholder="" value="" maxlength="100"/>
                    </div>

                    <div class="ui-form-item ui-form-item-textarea ui-border-b">
                        <label>
                            <span class="t_red">*</span>意见建议：
                        </label>
                        <textarea id="yjjy" placeholder="" maxlength="500"></textarea>
                    </div>

                    <div class="weui_cell_bd weui_cell_primary">
                        <div class="weui_uploader">

                            <p class="jfjj_tit">图片上传：<span class="bz">最多上传三张图片（每张照片不超过2M）</span></p>

                            <div class="weui_uploader_bd jfjj_upload">
                                <ul class="weui_uploader_files">
                                    <sapn id="images"></sapn>
                                </ul>

                                <div class="weui_uploader_input_wrp">

                                    <input class="weui_uploader_input" type="file" accept="image/jpg,image/jpeg,image/png,image/gif"
                                           multiple="multiple" onchange="changeimg(this.files)" name="uploadfiles" id="uploadfiles"/>

                                </div>

                            </div>

                        </div>
                    </div>

                </form>
            </div>

        </div>
    </div>

    <div class="ui-btn-wrap">
        <button id="save" class="ui-btn-lg ui-btn-primary">
            提交
        </button>
    </div>

</section>
</body>
</html>
